package com.mlizhi.modules.spec.setting;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.mlizhi.kingdom.R;
import com.mlizhi.utils.Constants;
import com.umeng.analytics.AnalyticsConfig;
import com.umeng.analytics.MobclickAgent;

/**
 * User: special
 * Date: 13-12-22
 * Time: 下午3:28
 * Mail: specialcyci@gmail.com
 */
public class SpecSettingAboutActivity extends Activity {

    private WebView aboutWebView;
    private ProgressBar pb;  
    @SuppressLint("SetJavaScriptEnabled")
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spec_setting_list_about);
        /** 发送策略定义了用户由统计分析SDK产生的数据发送回友盟服务器的频率。 */
        MobclickAgent.updateOnlineConfig( this );
        /** 设置是否对日志信息进行加密, 默认false(不加密). */
        AnalyticsConfig.enableEncrypt(true);
        aboutWebView = (WebView) findViewById(R.id.spec_setting_about_wv);
        pb = (ProgressBar) findViewById(R.id.spec_setting_about_pb);  
        pb.setMax(100);  
        WebSettings webSettings = aboutWebView.getSettings();
        aboutWebView.setWebViewClient(new SampleWebViewClient());
        aboutWebView.setWebChromeClient(new WebChromeClient(){
	        @Override  
	        public void onProgressChanged(WebView view, int newProgress) {  
	            pb.setProgress(newProgress);  
	            if(newProgress==100){  
	                pb.setVisibility(View.GONE);  
	            }  
	            super.onProgressChanged(view, newProgress);  
	        } 
		} );  
        webSettings.setJavaScriptEnabled(true);
        aboutWebView.loadUrl(Constants.URL_POST_SETTING_ABOUT_INFO+Constants.URL_POST_SETTING_ABOUT_VALUE);
        aboutWebView.setBackgroundColor(0);
        
    }

    private static final String insertJavaScript = "javascript:window.onload=function(){var imgs = document.getElementsByTagName(\"img\");for(var i=0;i<imgs.length;i++){imgs[i].style.width=\"100%\";}}";
    private static class SampleWebViewClient extends WebViewClient {
		
		 @Override  
		 public void onPageStarted(WebView view, String url, Bitmap favicon) {  
			 super.onPageStarted(view, url, favicon);  
			 //注入  
			 view.loadUrl(insertJavaScript);  
		 }  
		 
		 @Override
		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			// TODO Auto-generated method stub
			super.onReceivedError(view, errorCode, description, failingUrl);
			view.stopLoading();
			view.loadUrl("file:///android_asset/404.html"); 
			
		}
		 
    }
    /**
     * 退出当前页面
     * @param view
     */
    public void settingAbout2Main(View view) {
        finish();
    }
    @Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart("SplashScreen"); //统计页面(仅有Activity的应用中SDK自动调用，不需要单独写)
	    MobclickAgent.onResume(this);          //统计时长
	}

	@Override
	public void onPause() {
		super.onPause();
		 MobclickAgent.onPageEnd("SplashScreen"); // （仅有Activity的应用中SDK自动调用，不需要单独写）保证 onPageEnd 在onPause 之前调用,因为 onPause 中会保存信息 
		    MobclickAgent.onPause(this);
	}

}
